package com.wdciti.sccp.iot.tsdata.core.model;

import lombok.Data;
import lombok.NonNull;

import java.util.HashMap;
import java.util.Map;

/**
 * @author JINWEN
 */
@Data
public class Measurement {

    @NonNull
    private String key;
    private String name;
    @NonNull
    private DataType type;
    private Map<String, String> metadata;

    public Measurement(@NonNull String key, @NonNull DataType type) {
        this.key = key;
        this.type = type;
    }

    public Measurement(@NonNull String key, @NonNull DataType type, String name) {
        this.key = key;
        this.type = type;
        this.name = name;
    }

    public Measurement addMetadata(String key, String value) {
        if (metadata == null) {
            this.metadata = new HashMap<>();
        }
        metadata.put(key, value);
        return this;
    }

    public String getMetadata(String key) {
        if (metadata == null) {
            return null;
        } else {
            return this.metadata.get(key);
        }
    }

}
